package #PACKAGE#;

import java.util.ArrayList;
import java.util.List;

import org.apache.struts2.convention.annotation.Action;

import com.opensymphony.xwork2.ModelDriven;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;

import #MODEL_PKG#.#CLASSNAME#;

@Controller
@Scope("prototype")
@Component("#LOWER_CASENAME#Action")
@ParentPackage("json-default")
@Namespace(value = "/action/#LOWER_CASENAME#")
public class #CLASSNAME#EditorAction extends #CLASSNAME#Action implements ModelDriven<#CLASSNAME#>{

    private static final long serialVersionUID = #UID#L;
    private #CLASSNAME# model = new #CLASSNAME#();
    private Long id;

    @Override
    @Action(value = "editor", results = {
        @Result(name = "success", type = "json")})
    public String execute() throws Exception {
    	
    	#LOWER_CASENAME#Service.saveOrUpdate(model);
		return SUCCESS;
    }
    
    @Action(value = "updateAttr", results = {
            @Result(name = "success", type = "json")})
        public String updateAttr() throws Exception {
        	#LOWER_CASENAME#Service.updateAttr(attr, val, id);
    		return SUCCESS;
        }
    
    @Action(value = "delete", results = {
            @Result(name = "success", type = "json")})
        public String delete() throws Exception {
        	#LOWER_CASENAME#Service.delete(id);
    		return SUCCESS;
        }
    
    @Action(value = "attrDeletes", results = {
            @Result(name = "success", type = "json")})
        public String deletes() throws Exception {
    	//Object... val = null;
        	#LOWER_CASENAME#Service.attrDeletes(attr, val);
    		return SUCCESS;
        }
    
    @Action(value = "deleteBulk", results = {
            @Result(name = "success", type = "json")})
        public String deleteBulk() throws Exception {
    	List<#CLASSNAME#> list = new ArrayList<#CLASSNAME#>();
        	#LOWER_CASENAME#Service.deleteBulk(list);
    		return SUCCESS;
        }
    
    @Action(value = "get", results = {
            @Result(name = "success", type = "json")})
        public String get#CLASSNAME#() throws Exception {
        	#LOWER_CASENAME#Service.get(id);
    		return SUCCESS;
        }

    public void setModel(#CLASSNAME# model) {
        this.model = model;
    }

    public #CLASSNAME# getModel() {
        return model;
    }
    
    public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}
}
